// pages/home/home.js
import {request} from "../../utils/https"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    topWhiteHeight:wx.getMenuButtonBoundingClientRect()["bottom"],
    navList:[],
    pagenum:1,
    pagesize:6,
    goodsList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let topWhiteHeight= this.data.topWhiteHeight
    // console.log(topWhiteHeight);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let _self = this;
  
    _self.catitemsList() 
    _self.searchList()
  },
  // 4张图片数据
  catitemsList(){
    let _self = this;
    
    let data = {};

    request(
      "home/catitems",
      data,
      "GET",
      function(res){
        // console.log(res)
       _self.data.navList = res.data.message;
      //console.log(_self.data.navList)
       _self.setData({
        navList:_self.data.navList
       })
      }
    )
  },
  // 列表
  searchList(){
    let _self = this;
    let data = {
      pagenum:_self.data.pagenum,
      pagesize:_self.data.pagesize
    };
    request(
      "goods/search",
      data,
      "GET",
      function(res){
        console.log(res)
        _self.data.goodsList = [..._self.data.goodsList,...res.data.message.goods];
        _self.setData({
          goodsList:_self.data.goodsList
        })
      }
    )
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
      console.log("2222")
      let _self = this;
      _self.data.goodsList=[];
      _self.data.pagenum=1;
      _self.searchList()
  },
  togoodsDetail(e){
    console.log(e.detail)//e.detail 接收子组件传递过来的值

    let goodsid = e.detail;
    wx.navigateTo({
      url: '/pageage2/pages/shopDetails/shopDetails?id='+goodsid,
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    // console.log("1")
    let _self = this;
    _self.data.pagenum ++;
    _self.searchList()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})